package com.example.daiyinuo.leetcode;

import java.util.concurrent.Exchanger;

public class Client {
    public static void main(String[] args) {
        Exchanger exchanger = new Exchanger();

        new Thread(() -> {
            Object data = "公众号AAA";
            System.out.println(Thread.currentThread().getName() + data);
            try {
                data = exchanger.exchange(data);
                System.out.println(Thread.currentThread().getName() + data);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(() -> {
            Object data = "公众号BBB";
            System.out.println(Thread.currentThread().getName() + data);
            try {
                data = exchanger.exchange(data);
                System.out.println(Thread.currentThread().getName() + data);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(() -> {
            Object data = "公众号CCC";
            System.out.println(Thread.currentThread().getName() + data);
            try {
                data = exchanger.exchange(data);
                System.out.println(Thread.currentThread().getName() + data);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
